package com.chance.cc.crawler.development.bootstrap.bitauto.carType;

import com.chance.cc.crawler.core.CrawlerEnum;
import com.chance.cc.crawler.core.filter.FilterUtils;
import com.chance.cc.crawler.core.record.CrawlerRequestRecord;
import com.chance.cc.crawler.development.controller.DevCrawlerController;
import org.junit.Test;

import java.net.URLEncoder;

/**
 * @ClassName song
 * @Description TODO
 * @Author ding
 * @Date 2021/9/6 13:19
 * @Version 1.0
 * 易车站点车型数据采集
 **/
public class BitAutoCarTypeStart {

        public static void main(String[] args) {
            article();
           // gatherSeries();
        }

        private static final String domain = "bitauto";
        private static final String side = "carType";
        public static void gatherSeries() {
            String url = "https://car.yiche.com/";//
            CrawlerRequestRecord record = CrawlerRequestRecord.builder()
                    .startPageRequest(domain, CrawlerEnum.CrawlerRequestType.turnPage)
                    .httpUrl(url)
                    .domain(domain)
                    .filter(CrawlerEnum.CrawlerRecordFilter.dateRange)
                    .addFilterInfo(FilterUtils.dateRangeFilterInfo(24 * 30, null))
                    .resultLabelTag(CrawlerEnum.CrawlerDataType.article)
                    .resultLabelTag(CrawlerEnum.CrawlerDataType.interaction)
                    .resultLabelTag(CrawlerEnum.CrawlerDataType.comment)
                    .build();
            record.setNeedWashPage(true);
            record.tagsCreator().bizTags().addSite(side);
            record.tagsCreator().bizTags().addSiteBiz(side);
            record.tagsCreator().bizTags().addDomain(domain);


            CrawlerRequestRecord keywordRecord = CrawlerRequestRecord.builder()
                    .startPageRequest(domain, CrawlerEnum.CrawlerRequestType.turnPageItem)
                    .httpUrl("http://192.168.1.215:9599/v1/meta/bitauto/keys?site=carType")
                    .requestLabelTag(CrawlerEnum.CrawlerRequestType.supportSource)
                    .requestLabelTag(CrawlerEnum.CrawlerRequestType.internalDownload)
                    .build();


            DevCrawlerController.builder()
                    .triggerInfo(domain, domain, System.currentTimeMillis(), domain)
                    .crawlerThreadNum(5)
                    .crawlerRequestQueue(DevCrawlerController.devRequestQueue(domain))
                    .consoleResultPipeline("kafka")
                    .fileResultPipeline("kafka", "F:\\chance_log\\bitauto\\carType\\data.log", false)
                    .requestRecord(record)
                   // .supportRecord(keywordRecord)
                    .build("com.chance.cc.crawler.development.scripts.bitauto")
                    .start();
        }

    public static void article() {
        String url = "https://car.yiche.com/alfaromeo/";//爱卡汽车网
        //String url = "https://car.yiche.com/jilikx11/";//爱卡汽车网
        CrawlerRequestRecord record = CrawlerRequestRecord.builder()
                .startPageRequest(domain, CrawlerEnum.CrawlerRequestType.turnPage)
                .httpUrl(url)
                .domain(domain)
                .filter(CrawlerEnum.CrawlerRecordFilter.dateRange)
                .addFilterInfo(FilterUtils.dateRangeFilterInfo(24 * 30, null))
                .resultLabelTag(CrawlerEnum.CrawlerDataType.article)
                .resultLabelTag(CrawlerEnum.CrawlerDataType.interaction)
                .resultLabelTag(CrawlerEnum.CrawlerDataType.comment)
                .build();
        record.setNeedWashPage(true);
        record.tagsCreator().bizTags().addSite(side);
        record.tagsCreator().bizTags().addSiteBiz(side);
        record.tagsCreator().bizTags().addDomain(domain);

        CrawlerRequestRecord keywordRecord = CrawlerRequestRecord.builder()
                .startPageRequest(domain, CrawlerEnum.CrawlerRequestType.turnPageItem)
                .httpUrl("http://192.168.1.217:9599/v1/meta/bitauto/keys?site=adhocKw")
                .requestLabelTag(CrawlerEnum.CrawlerRequestType.supportSource)
                .requestLabelTag(CrawlerEnum.CrawlerRequestType.internalDownload)
                .build();


        DevCrawlerController.builder()
                .triggerInfo(domain, domain, System.currentTimeMillis(), domain)
                .crawlerThreadNum(10)
                .crawlerRequestQueue(DevCrawlerController.devRequestQueue(domain))
                .consoleResultPipeline("kafka")
                .fileResultPipeline("kafka", "F:\\chance_log\\bitauto\\carType\\article.log", false)
                .requestRecord(record)
               // .supportRecord(keywordRecord)
                .build("com.chance.cc.crawler.development.scripts.bitauto")
                .start();
    }
        @Test
        public void  中文(){
            String seriesId = "7348";
            String param = "{\"serialId\":\""+seriesId+"\"}";
            param = URLEncoder.encode(param);
            System.out.println(param);
        }
}
